package com.zk.ppa.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author feng
 */
@Configuration
public class Swagger3Config {
    @Bean
    public Docket createRestApi(Environment environment){
        Profiles profiles = Profiles.of("dev", "test");
        boolean enableSwagger = environment.acceptsProfiles(profiles);
        //如果是dev或者test则开启swagger，否则关闭
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .enable(enableSwagger)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zk.ppa"))
                //扫描包中的接口
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("精准扶贫Swagger Api文档")
                .description("不知道你贫不贫，反正我贫了")
                .version("3.0")
                .build();
    }
}
